package com.itheima.a04test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class Test4 {
    public static void main(String[] args) throws ParseException {
        /*计算活了多少天，使用jdk7和jdk8两种方式*/

        //jdk7
        //获取现在的时间毫秒值
        long now = System.currentTimeMillis();
        //出生年月日
        String str1="2004年12月10日";
        //用那啥解析再转为date对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date d1 = sdf.parse(str1);
        //毫秒值相减进行计算
        long l = now - d1.getTime();
        System.out.println(l/1000/60/60/24L);

        //jdk8
        //获取时间对象
        LocalDate ld1 = LocalDate.of(2004, 12, 10);
        LocalDate ld2 = LocalDate.now();

        long between = ChronoUnit.DAYS.between(ld1, ld2);
        System.out.println(between);

    }
}
